package org.dei.perla.rockfall.gui.queryforge.panels;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import org.dei.perla.rockfall.gui.queryforge.ReadableStatusPanel;

public class RunningStatus2Panel extends ReadableStatusPanel {

	private JCheckBox jCheckBox1;
	private JComboBox jComboBox2;
	private JComboBox jComboBox3;
	private JComboBox jComboBox4;

	public RunningStatus2Panel(String title) {
		super(title);
		// TODO Auto-generated constructor stub
	}

	@Override
	public int getStatus() {
		int retvalue = 0;
		
		boolean check1 = this.jCheckBox1.isSelected();

		int combo2 = this.jComboBox2.getSelectedIndex();
		int combo3 = this.jComboBox3.getSelectedIndex();
		int combo4 = this.jComboBox4.getSelectedIndex();
		
		if(check1)
			retvalue |= 0x1;
				
		switch(combo2){
			case 0:{
				retvalue |= 0x0010;
				break;
			}
			case 1:{
				retvalue |= 0x0020;
				break;
			}
			case 2:{
				retvalue |= 0x0030;
				break;
			}
			case 3:{
				retvalue |= 0x0040;
				break;
			}
			case 4:{
				retvalue |= 0x0050;
				break;
			}
			case 5:{
				retvalue |= 0x0060;
				break;
			}
			case 6:{
				retvalue |= 0x0070;
				break;
			}
			case 7:{
				retvalue |= 0x0080;
				break;
			}
			default:{
				break;
			}
		}
		
		switch(combo3){
			case 0:{
				retvalue |= 0x0100;
				break;
			}
			case 1:{
				retvalue |= 0x0200;
				break;
			}
			case 2:{
				retvalue |= 0x0300;
				break;
			}
			case 3:{
				retvalue |= 0x0400;
				break;
			}
			case 4:{
				retvalue |= 0x0500;
				break;
			}
			case 5:{
				retvalue |= 0x0600;
				break;
			}
			case 6:{
				retvalue |= 0x0700;
				break;
			}
			default:{
				break;
			}
		}
		switch(combo4){
			case 0:{
				retvalue |= 0x0000;
				break;
			}
			case 1:{
				retvalue |= 0x1000;
				break;
			}
			case 2:{
				retvalue |= 0x2000;
				break;
			}
			case 3:{
				retvalue |= 0x3000;
				break;
			}
			
		}
		return retvalue;
	}

	@Override
	public void setStatus(int stato) {
		try{
		this.jCheckBox1.setSelected((stato&0x1)>0);
		this.jComboBox2.setSelectedIndex(((stato/0x10)-1)&0xF);
		this.jComboBox3.setSelectedIndex(((stato/0x100)-1)&0xF);
		this.jComboBox4.setSelectedIndex(((stato/0x1000))&0xF);
		}catch (Exception e) {
			System.out.println(stato);
			e.printStackTrace();
		}
	}

	@Override
	protected void setupInternalComponents() {
		
		//Primo blocco di scelte
		
		jCheckBox1 = new JCheckBox();
		jCheckBox1.setSelected(true);
		JLabel jlabel1 = new JLabel("Abilitazione trigger in aquisizione");
		JPanel jpanel1 = new JPanel();
		BoxLayout layout1 = new BoxLayout(jpanel1, BoxLayout.X_AXIS);
		jpanel1.add(jlabel1);
		jpanel1.add(jCheckBox1);
		
		//Secondo Blocco di scelte
		
		jComboBox2 = new JComboBox();
		jComboBox2.setEditable(false);
		jComboBox2.addItem("16 campioni");
		jComboBox2.addItem("32 campioni");
		jComboBox2.addItem("64 campioni");
		jComboBox2.addItem("128 campioni");
		jComboBox2.addItem("256 campioni");
		jComboBox2.addItem("512 campioni");
		jComboBox2.addItem("1024 campioni");
		jComboBox2.addItem("2048 campioni");
		jComboBox2.setSelectedIndex(5);
		
		JLabel jlabel2 = new JLabel("Imposta lunghezza finestra di acquisizione");
		JPanel jpanel2 = new JPanel();
		BoxLayout layout2 = new BoxLayout(jpanel2, BoxLayout.X_AXIS);
		jpanel2.add(jlabel2);
		jpanel2.add(jComboBox2);
		
        //Terzo Blocco di scelte
		
		jComboBox3 = new JComboBox();
		jComboBox3.setEditable(false);
		jComboBox3.addItem("solo asse X abilitato");
		jComboBox3.addItem("solo asse Y abilitato");
		jComboBox3.addItem("solo asse Z abilitato");
		jComboBox3.addItem("solo assi X e Y abilitati");
		jComboBox3.addItem("solo asse X e Z abilitati");
		jComboBox3.addItem("solo asse Y e Z abilitati");
		jComboBox3.addItem("X, Y e Z abilitato");
		jComboBox3.setSelectedIndex(6);
		
		JLabel jlabel3 = new JLabel("Imposta tipo di riempimento buffer segnale");
		JPanel jpanel3 = new JPanel();
		BoxLayout layout3 = new BoxLayout(jpanel3, BoxLayout.X_AXIS);
		jpanel3.add(jlabel3);
		jpanel3.add(jComboBox3);
		
		//Quarto blocco di scelte
		
		jComboBox4 = new JComboBox();
		jComboBox4.setEditable(false);
		jComboBox4.addItem("niente pretrigger");
		jComboBox4.addItem("8 campioni");
		jComboBox4.addItem("16 campioni");
		jComboBox4.addItem("32 campioni");
		jComboBox4.setSelectedIndex(3);
		
		JLabel jlabel4 = new JLabel("Imposta lunghezza finestra di pretrigger");
		JPanel jpanel4 = new JPanel();
		BoxLayout layout4 = new BoxLayout(jpanel4, BoxLayout.X_AXIS);
		jpanel4.add(jlabel4);
		jpanel4.add(jComboBox4);
		
		//aggiungo tutti i blocchi
		this.add(jpanel1);
		this.add(jpanel2);
		this.add(jpanel3);
		this.add(jpanel4);		
	}

}
